<%--
  Created by IntelliJ IDEA.
  User: LLS
  Date: 2020/1/2
  Time: 10:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>表单外部数据源树组件</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/js/limstree.js" type="text/javascript" charset="utf-8"></script>
</head>
<style>
    body {
        background-color: #fbfbfb;
    }
</style>
<body>

<div class="main-row">
    <div class="side-col">
        <div class="panel  rtfix">
            <div class="panel-heading">
                <div class="panel-title maintit">外部数据源</div>
            </div>
            <div class="panel-body">
                <div class="eleTree ele1" lay-filter="data1"></div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    var el
        ,nodefun = new Classmeth();
    var datas;

    layui.use(['eleTree'], function(){
        var eleTree = layui.eleTree
            ,$ = layui.jquery;



        //        初始化渲染
        el = eleTree.render({
            elem: '.ele1',
            highlightCurrent: true,
            showLine:true,
            url:'/TerpServerController/selectDbServerNameTerpServer',
            lazy: true,
            load: function(data,callback) {
                datas=data;
                $.post('/TerpServerController/findtablAll',{serverId:data.id,dbDataBaseName:data.label,pId:data.pId},function (res) {
                    callback(res.object);//点击节点回调
                    if(res.object) nodefun.objLen = res.object.length
                    else nodefun.objLen = 0;
                })
            },
            done:function (data) { //渲染完成回调
                if(data.data) nodefun.objLen = data.data.length
                else nodefun.objLen = 0;
            },
            response: {
                dataName: "object"
            }
        });

        // 节点点击事件
        eleTree.on("nodeClick(data1)",function(d) {
            var obj = d.data.currentData;
           if (obj.isLeaf){
               debugger
               $("#dataSrcName",opener.document).val(obj.label); //赋值父页面
               window.opener.addtable(obj.label,datas.label,obj.id);
               window.close();
           }
           if (obj.pId==='0'){
               $("#dataSrcName",opener.document).attr("terpId",obj.id); //赋值父页面
           }
        });

    });
</script>
</body>
</html>
